package com.ysdcrm.crm.controller;

import java.util.List;

import javax.annotation.Resource;

import com.ysdcrm.crm.mapper.IModulesMapper;
import com.ysdcrm.crm.model.Modules;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;

@RestController
@ApiOperation(value = "模块管理")
@RequestMapping("module")
public class ModulesController {
    @Resource
    private IModulesMapper mapper;

    @GetMapping
    @ApiOperation(value = "查询所有模块")
    public List<Modules> findAll(){
        return mapper.findAll();
    }

    @PostMapping
    @ApiOperation(value = "添加模块",notes = "名称不可重复")
    public int add(Modules m){
        if(mapper.getNameCount(m.getName())>0){
            return 0;
        }else{
            return mapper.insert(m);
        }
    }

    @PutMapping
    @ApiOperation(value = "修改模块信息",notes = "名称不能重复")
    public int edit(Modules m){
        if(mapper.getNameCount(m.getName())>0){
            return 0;
        }else{
            return mapper.updateById(m);
        }
    }

    @DeleteMapping
    @ApiOperation(value = "删除模块",notes = "逻辑删除")
    public int del(int mid){
        return mapper.del(mid);
    }
}
